package com.warmheart.core.ex.base;

import com.warmheart.core.enums.WhEnum;

/**
 * 
 * @ClassName: CoreWhException
 * @Description: 核心异常，所有响应码为整数型的异常均应继承该类并实现默认核心枚举方法
 * @author ZhangJianyang
 * @date 2025-06-16 09:37:02
 *
 */
public abstract class CoreWhException extends RuntimeException implements WhException<Integer> {

    private static final long serialVersionUID = 1L;

    /**
     * 异常枚举
     */
    private WhEnum<Integer> whEnum;

    public CoreWhException() {
    }

    public CoreWhException(Throwable e) {
        super(e);
    }

    public CoreWhException(String message) {
        super(message);
    }

    public CoreWhException(String message, Throwable e) {
        super(message, e);
    }

    public CoreWhException(WhEnum<Integer> whEnum) {
        super(whEnum.getDesc());
        this.whEnum = whEnum;
    }

    public CoreWhException(WhEnum<Integer> whEnum, Throwable e) {
        super(whEnum.getDesc(), e);
        this.whEnum = whEnum;
    }

    @Override
    public WhEnum<Integer> getWhEnum() {
        if (this.whEnum == null) {
            this.whEnum = this.coreWhEnum();
        }
        return this.whEnum;
    }
}
